package com.hx01.modules.manager.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hx01.common.annotation.SysLog;
import com.hx01.modules.manager.entity.DishSpecEntity;
import com.hx01.modules.manager.service.DishSpecService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 菜品规格 菜品规格(DishSpec)表控制层
 *
 * @author makejava
 * @since 2020-12-25 22:59:03
 */
@RestController
@RequestMapping("dishSpec")
@Api(tags = "菜品规格 菜品规格")
public class DishSpecController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private DishSpecService dishSpecService;

    /**
     * 分页查询所有数据
     *
     * @param page     分页对象
     * @param dishSpec 查询实体
     * @return 所有数据
     */
    @GetMapping("/list")
    @ApiOperation("分页查询所有数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页大小", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "desc", value = "倒序排序字段与asc二选一，排序字段需要驼峰转换成下划线", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "asc", value = "正序排序字段与desc二选一, 排序字段需要驼峰转换成下划线", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "id", value = "主键", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "storeId", value = "店铺ID", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "dishSpecTypeId", value = "菜品规格分类ID", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "specName", value = "规格名称", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "fluctuationPrice", value = "浮动价格", required = false, dataTypeClass = Double.class),
            @ApiImplicitParam(name = "sorting", value = "排序值", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "revision", value = "乐观锁", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "status", value = "数据状态 0禁用 1正常", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "createUserId", value = "创建人", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "createUserTime", value = "创建时间", required = false, dataTypeClass = Date.class),
            @ApiImplicitParam(name = "updateUserId", value = "更新人", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", required = false, dataTypeClass = Date.class),
    })
    public R selectAll(Page<DishSpecEntity> page, DishSpecEntity dishSpec) {
        return success(this.dishSpecService.page(page, new QueryWrapper<>(dishSpec)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @ApiOperation("通过主键查询单条数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "数据主键id", required = true, dataTypeClass = String.class)
    })
    public R selectOne(@PathVariable Serializable id) {
        return success(this.dishSpecService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param dishSpec 实体对象
     * @return 新增结果
     */
    @SysLog("新增数据")
    @PostMapping("/save")
    @ApiOperation("新增数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "storeId", value = "店铺ID", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "dishSpecTypeId", value = "菜品规格分类ID", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "specName", value = "规格名称", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "fluctuationPrice", value = "浮动价格", required = false, dataTypeClass = Double.class),
            @ApiImplicitParam(name = "sorting", value = "排序值", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "revision", value = "乐观锁", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "status", value = "数据状态 0禁用 1正常", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "createUserId", value = "创建人", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "createUserTime", value = "创建时间", required = false, dataTypeClass = Date.class),
            @ApiImplicitParam(name = "updateUserId", value = "更新人", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", required = false, dataTypeClass = Date.class),
    })
    public R insert(@RequestBody DishSpecEntity dishSpec) {
        return success(this.dishSpecService.save(dishSpec));
    }

    /**
     * 修改数据
     *
     * @param dishSpec 实体对象
     * @return 修改结果
     */
    @SysLog("修改数据")
    @PostMapping("/update")
    @ApiOperation("修改数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "storeId", value = "店铺ID", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "dishSpecTypeId", value = "菜品规格分类ID", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "specName", value = "规格名称", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "fluctuationPrice", value = "浮动价格", required = false, dataTypeClass = Double.class),
            @ApiImplicitParam(name = "sorting", value = "排序值", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "revision", value = "乐观锁", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "status", value = "数据状态 0禁用 1正常", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "createUserId", value = "创建人", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "createUserTime", value = "创建时间", required = false, dataTypeClass = Date.class),
            @ApiImplicitParam(name = "updateUserId", value = "更新人", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", required = false, dataTypeClass = Date.class),
    })
    public R update(@RequestBody DishSpecEntity dishSpec) {
        return success(this.dishSpecService.updateById(dishSpec));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @SysLog("删除数据")
    @PostMapping("/delete")
    @ApiOperation("删除数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "idList", value = "主键数据集合", required = true, dataTypeClass = List.class)
    })
    public R delete(@RequestParam("idList") List<Long> idList) {
        return success(this.dishSpecService.removeByIds(idList));
    }
}